﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SangaiTech.Abstractions;
using Moq;
using System.Collections.Generic;
using System.Linq;
using SimpleInjector;

namespace SangaiTech.Core.DomainServices.Tests
{
    [TestClass]
    public class EmployeeServiceTest
    {
        public static Container _container;
        [ClassInitialize]
        public static void EmployeeServiceTest_Init(TestContext context)
        {
            _container = new Container();
            _container.Register<IEmployeeRepository>(() =>
            {
                var  mockEmployeeRepository=new Mock<IEmployeeRepository>();
                mockEmployeeRepository.Setup(r => r.All()).Returns(MockEmployees());
                return mockEmployeeRepository.Object;
            });
            SangaiTech.Core.Bootstrapper.Register(_container);
            _container.Verify();
        }

        [TestMethod]
        public void TestGetAllRetiredEmployees()
        {

            var employeeService = _container.GetInstance<IEmployeeService>();

            var retiredEmployees = employeeService.GetAllRetiredEmployees().ToList();
            Assert.AreEqual(1, retiredEmployees.Count);
            Assert.AreEqual("ram", retiredEmployees[0].FirstName);
        }

        public static IQueryable<Employee> MockEmployees()
        {
            var employees = new Employee[]{
                new Employee{ EmployeeId=1, FirstName="ram", LastName="singh", IsRetired=true, RetirementDate=DateTime.Today},
                new Employee{ EmployeeId=2, FirstName="shyam", LastName="singh", IsRetired=false}
            };
            return employees.AsQueryable();
        }
    }
}
